<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function sum(a, b, c, d) {
            return a + b + c + d
        }

        function curry(func, ...args) {
            return function (...sunArgs) {
                const allArgs = [...args, ...sunArgs]
                if (allArgs.length >= func.length) {
                    //参数够了执行
                    return func(...allArgs)
                }
                else {
                    //参数不够，继续固定
                    return curry(func, ...allArgs)
                }
            }
        }


        //curry：柯里化，用户固定某个函数前面的参数，得到新的一个函数，新的函数调用时，接收剩余参数

        const sum1 = curry(sum, 1)
        console.log(sum1(6, 7, 8, 9));  
        const sum2 = sum1(2, 3)
        const sum3 = sum2(4)

        console.log(sum3);



    </script>
</body>

</html>